package cn.zyq.ykb.controller.mgt.config;

import cn.zyq.ykb.beans.config.ConfigProp;
import org.springframework.security.access.prepost.PreAuthorize;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.service.config.ConfigPropService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zyq.ykb.system.common.PageParam;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 配置- 道具Controller
 *
 * @author SystemAuth
 * @date 2023-05-30
 */

@RestController(value = "MgtConfigPropController")
@RequestMapping("/mgt/configProp")
@Api(tags = "配置- 道具接口")
public class ConfigPropController extends BaseController {

    @Autowired
    private ConfigPropService configPropService;

    /**
     * 查询配置- 道具列表
     */
    @ApiOperation(value = "列表", response = ConfigProp.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.configPropService.selectConfigPropList(pageParam);
    }

     /**
      * 导出配置- 道具列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "配置- 道具" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, ConfigProp configProp) {
         List<ConfigProp> list = configPropService.selectConfigPropList(configProp);
         ExcelUtil<ConfigProp> util = new ExcelUtil<ConfigProp>(ConfigProp. class);
         util.exportExcel(response, list, "配置- 道具数据");
     }

    /**
     * 获取配置- 道具详细信息
     */
    @ApiOperation(value = "详情", response = ConfigProp.class)
    @GetMapping(value = "/{configPropID}")
    public Object getInfo(@PathVariable("configPropID") Integer configPropID) {
        return this.configPropService.selectConfigPropByConfigPropID(configPropID);
    }
    /**
     * 获取配置- 道具详细信息
     */
    @ApiOperation(value = "详情", response = ConfigProp.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.configPropService.selectConfigPropByServiceID(serviceID);
    }

    /**
     * 新增配置- 道具
     */
    @ApiOperation(value = "新增")
    @Log(title = "配置- 道具", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody ConfigProp configProp) {
        return this.configPropService.insertConfigProp(configProp);
    }

    /**
     * 修改配置- 道具
     */
    @ApiOperation(value = "编辑")
    @Log(title = "配置- 道具", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody ConfigProp configProp) {
        return this.configPropService.updateConfigProp(configProp);
    }

    /**
     * 删除配置- 道具
     */
    @ApiOperation(value = "删除")
    @Log(title = "配置- 道具", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configPropIDs}")
    public Object remove(@PathVariable Integer[] configPropIDs) {
        return this.configPropService.deleteConfigPropByConfigPropIDs(configPropIDs);
    }
}
